From: Florian Müllner Date: Thu, 27 Feb 2020 21:46:44 +0000 (-0800) Subject: environment: reduce calls to g_time_zone_new_local() X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~772^2^2~16 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=06b690ff21204ea9ea26d2671eb26b1a1f24caa9;p=gnome-shell.git environment: reduce calls to g_time_zone_new_local() Creating a new GTimeZone for the local timezone can be quite expensive if done repeatedly. It requires an open(), mmap(), and parsing of /etc/localtime. This patch was provided by Florian, and I've tested it as far back as 3.28.4 to ensure that we are really reducing the number of open() calls on the compositor thread. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/1051 Signed-off-by: Christian Hergert --- diff --git a/js/ui/environment.js b/js/ui/environment.js index ba378e7d1..8ab9e7d44 100644 --- a/js/ui/environment.js +++ b/js/ui/environment.js @@ -12,6 +12,9 @@ imports.gi.versions.TelepathyLogger = '0.2'; const { Clutter, GLib, GObject, Meta, Shell, St } = imports.gi; const Gettext = imports.gettext; +const System = imports.system; + +let _localTimeZone = null; // We can't import shell JS modules yet, because they may have // variable initializations, etc, that depend on init() already having @@ -304,9 +307,25 @@ function init() { } }; + // Override to clear our own timezone cache as well + const origClearDateCaches = System.clearDateCaches; + System.clearDateCaches = function () { + _localTimeZone = null; + origClearDateCaches(); + }; + // Work around https://bugzilla.mozilla.org/show_bug.cgi?id=508783 Date.prototype.toLocaleFormat = function (format) { - let dt = GLib.DateTime.new_from_unix_local(this.getTime() / 1000); + if (_localTimeZone === null) + _localTimeZone = GLib.TimeZone.new_local(); + + let dt = GLib.DateTime.new(_localTimeZone, + this.getYear(), + this.getMonth() + 1, + this.getDate(), + this.getHours(), + this.getMinutes(), + this.getSeconds()); return dt ? dt.format(format) : ''; };